#include "ControleConsole.h"

using namespace std;

ControleConsole::ControleConsole()
{
	m_derniereCoordonnees.first = 0;
	m_derniereCoordonnees.second = 0;
}

ControleConsole::ControleConsole(Vue* vue, Modele* modele)
{
	m_vue = vue;
	m_modele = modele;
}

void ControleConsole::faireAction()
{	
	int action;
	if(!(cin>>action))
	{
		string tmp;
		cin.clear();
		cin >> tmp;
		cout<<"Vous ne pouvez rentrer qu'un chiffre"<<endl; 
	}
	//Permet de se balader dans le menu
	if(actionDisponible(action))
	{
		switch(action)
		{
			case 1:
				m_modele->setMenu(new Action());
			break;
			case 2:
				m_modele->setMenu(new Systeme());
			break;
			case 11:
				m_modele->setMenu(new Combat());
			break;
			case 12:
				m_modele->setMenu(new Deplacement());
			break;
			case 13:
				m_modele->setMenu(new Gestion());
			break;
			case 14:
				m_modele->setMenu(new Interagir());
			break;
			case 24:
				//~ m_modele->setMenu(new Interagir());options
			break;
			//plus des options donc réinitialiser le menu ainsi que l'ajout d'action
			case 21:
				//~ m_modele->setMenu(new Interagir());quitter
				effacerAjouter();
			break;
			case 22:
				//~ m_modele->setMenu(new Interagir());sauvegarder
				effacerAjouter();
			break;
			case 23:
				//~ m_modele->setMenu(new Interagir());charger
				effacerAjouter();
			break;
			case 111:
				//~ m_modele->setMenu(new Interagir()); attaquer
				effacerAjouter();
			break;
			case 121://se deplace nord
				m_modele->setMenu(new Menu());
				effacerAjouter();
				deplacer(0,-1);
			break;
			case 122://se deplace sud
				m_modele->setMenu(new Menu());
				effacerAjouter();
				deplacer(0,1);
			break;
			case 123://se deplace est
				m_modele->setMenu(new Menu());
				effacerAjouter();
				deplacer(1,0);
			break;
			case 124://se deplace ouest
				m_modele->setMenu(new Menu());
				effacerAjouter();
				deplacer(-1,0);
			break;
			case 125:
				effacerAjouter();
				//~ deplacer(-1,0);monter
			break;
			case 126://descendre
				m_modele->setMenu(new Menu()); // réinitianilise le menu
				effacerAjouter();
				m_modele->changementMap(false);
			break;
			case 127:
				effacerAjouter();
				//~ deplacer(-1,0);nager
			break;
			case 131:
				//~ m_modele->setMenu(new Interagir());dormir
				effacerAjouter();
			break;
			case 132:
				//~ m_modele->setMenu(new Interagir()); manger
				effacerAjouter();
			break;
			case 141:
				//~ m_modele->setMenu(new Interagir());parler
				effacerAjouter();
			break;
			case 142://couper arbre
				m_modele->setMenu(new Menu());
				effacerAjouter();
				dynamic_cast<Arbre*>(m_modele->getMap()[m_derniereCoordonnees.first][m_derniereCoordonnees.second])->couper();
			break;
			case 143://ouvrir porte
				m_modele->setMenu(new Menu());
				effacerAjouter();
				dynamic_cast<Porte*>(m_modele->getMap()[m_derniereCoordonnees.first][m_derniereCoordonnees.second])->ouvrir();
			break;
			case 144:
				effacerAjouter();
				//~ m_modele->setMenu(new Interagir());renverser
			break;
			case 145://fermer porte
				m_modele->setMenu(new Menu());
				effacerAjouter();
				dynamic_cast<Porte*>(m_modele->getMap()[m_derniereCoordonnees.first][m_derniereCoordonnees.second])->fermer();

			break;
			default:
				m_modele->setMenu(new Menu());
			break;		
			
		}
	}
	else
		cout<<"action non disponible"<<endl;
		
	//une fois les actions effectué, on regarde si on a des actions speciales
	int tx = m_modele->getPersonnageX();
	int ty = m_modele->getPersonnageY();
	Case* acces = m_modele->getMap()[ty][tx];
	ajouterAAjouter(acces);

	for(int i = 0 ; i < m_ajouter.size() ; i++)
	{
		m_modele->addElemMenu(m_ajouter[i]);
	}
	
}

